//判断cookie中是否有对应的key(有参:key, 有返: true或者false)
export default {
	hasKey:function(key){
		var strArr = document.cookie.split(";");
		for (var i = 0; i < strArr.length; i++) {
			var kvArr = strArr[i].split("=");
			if(kvArr[0].trim() == key){
				//相等
				return true;
			}
		}
		//不相等
		return false;
	},
	getValueByKey:function(key){
		//获取所有键值对
		var strArr = document.cookie.split(";");
		for (var i = 0; i < strArr.length; i++) {
			var kvArr = strArr[i].split("=");
			if(kvArr[0].trim() == key){
				return kvArr[1];
			}
		}
	},
	addCookie:function(k, v, t){
		if(typeof t == "number"){
			//max-age
			document.cookie = k + "=" + v +";max-age=" + t;
		}else{
			//expires
			document.cookie = k + "=" + v +";expires=" + t.toString();
		}
	},
	deleteCookie:function(key){
		document.cookie = key + "=;max-age=-1";
	}
	
}














